package model

import (
	"gorm.io/gorm"
	"time"
	"user_service/global"
)

type Works struct {
	Id          uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Name        string         `gorm:"column:name;type:varchar(20);not null;" json:"name"`
	Describe    string         `gorm:"column:describe;type:varchar(50);not null;" json:"describe"`
	Association string         `gorm:"column:association;type:varchar(50);not null;" json:"association"`
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (w *Works) TableName() string {
	return "works"
}

func (w *Works) GetUserBy(name string) error {
	return global.DB.Where("name=?", name).Limit(1).First(&w).Error
}

func (w *Works) Create() error {
	return global.DB.Create(&w).Error
}
